package com.example.jn_dxs.Ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.jn_dxs.Base.BaseActivity;
import com.example.jn_dxs.Base.BaseViewModel;
import com.example.jn_dxs.Bean.PopuBean;
import com.example.jn_dxs.Bean.WaterLevelBean;
import com.example.jn_dxs.Bean.WaterQualityBean;
import com.example.jn_dxs.Bean.WaterTemperatureBean;
import com.example.jn_dxs.R;
import com.example.jn_dxs.Ui.adapter.PopuAdapter;
import com.example.jn_dxs.Utlis.PopWindowUtil;
import com.example.jn_dxs.ViewModel.StatisticsVM;
import com.example.jn_dxs.databinding.ActivityStatisticsBinding;

import java.util.ArrayList;
import java.util.List;

public class StatisticsActivity extends BaseActivity<StatisticsVM, ActivityStatisticsBinding> {


    @Override
    protected int getLayoutId() {
        return R.layout.activity_statistics;
    }

    @Override
    protected void initEventAndView() {
        binding.MyTopBar.tvBack.setOnClickListener(v -> finish());
        binding.MyTopBar.tvTitle.setText("详细信息");
        if (!getIntent().getStringExtra("id").isEmpty()) {
            model.getDetail(getIntent().getStringExtra("id"));
            binding.DrillingNumber.setText(getIntent().getStringExtra("id"));
        }
    }

    @Override
    public void initClick() {

    }

    @Override
    protected void onObjectDataChange(JSONObject object) {
        super.onObjectDataChange(object);
        JSONObject dtgcjbqkList = object.getJSONObject("dtgcjbqkList");
        JSONArray sweis = object.getJSONArray("sweis");  //位
        JSONArray swens = object.getJSONArray("swens");  //温
        JSONArray szs = object.getJSONArray("szs");
        if (dtgcjbqkList != null) {
            binding.GeographicLocation.setText(dtgcjbqkList.getString("tkalb"));  //位置
            binding.Longitude.setText(dtgcjbqkList.getString("chahba"));  //经度
            binding.Dimension.setText(dtgcjbqkList.getString("chahbb"));  //维度
            binding.Type.setText(dtgcjbqkList.getString("swefc"));   //检测类型
            binding.Content.setText(dtgcjbqkList.getString("sweb"));  //检测内容
        }

        if (!sweis.isEmpty() && sweis.size() > 0) { //位
            WaterLevelBean waterLevelBean = JSON.parseObject(sweis.getJSONObject(0).toJSONString(), WaterLevelBean.class);
            binding.ObservationTimeWei.setText(waterLevelBean.getEndjcsj());
            binding.HighWaterLevel.setText(waterLevelBean.getShuiwei() + "m");

        }
        if (!swens.isEmpty() && swens.size() > 0) {  //温
            WaterTemperatureBean waterTemperatureBean = JSON.parseObject(swens.getJSONObject(0).toJSONString(), WaterTemperatureBean.class);
            binding.ObservationTimeWen.setText(waterTemperatureBean.getEndjcsj());
            binding.WaterTemperature.setText(waterTemperatureBean.getSw() + "℃");
        }
        if (!szs.isEmpty() && szs.size() > 0) {  //质量
            WaterQualityBean waterQualityBean = JSON.parseObject(szs.getJSONObject(0).toJSONString(), WaterQualityBean.class);
            binding.PH.setText(waterQualityBean.getSwfha());
            binding.TotalHardness.setText(waterQualityBean.getSwfhda());
            binding.Organophosphorus.setText(waterQualityBean.getMdcebb());
            binding.TotalAlkalinity.setText(waterQualityBean.getPkjfs());
        }
    }
}
